import { Part } from './../../data/MomData';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root'
})
export class PurchaseService {
  GetPurchaseRequirements(arg0: { RequirementNum: string; PageNumber: number; PageSize: number; }) {
    throw new Error('Method not implemented.');
  }
  GetPurchaseArrivals(arg0: { ArrivalNum: string; PageNumber: number; PageSize: number; }) {
    throw new Error('Method not implemented.');
  }
  GetPurchaseReturns(arg0: { ReturnNum: string; PageNumber: number; PageSize: number; }) {
    throw new Error('Method not implemented.');
  }
  data = '/Supply'
  constructor(private http:HttpClient ) { }
  getPurchaseRequirement(filter:{
    PageSize?:number,
    PageNumber?:number,
    PurchaseRequiredNum?:string,
    PartNumPartName?:string,
    PurchaseManNumPurchaseManName?:string,
    Status?:string,
    isClosed?:boolean,
    StartTime?:string,
    EndTime?:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseRequiredOrderWithSub', {params:filter})
  }//获取采购需求

  addPurchaseRequirement(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreatePurchaseRequiredOrder', data)
  }//新增采购需求
  getPurchaseRequirementById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseRequiredOrderById', {params:{purchaseRequiredOrderId:id}})
  }//获取采购需求详情
  editPurchaseRequirement(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdatePurchaseRequiredOrder', data, {params:{purchaseRequiredOrderId:id}})
  }//编辑采购需求
  closePurchaseRequirement(idS:any){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseRequirement', idS)
  }//结案采购需求
  auditPurchaseRequirement(state:any,ids:any){
    return this.http.put(environment.apiUrl + this.data + '/ChangePurchaseRequiredOrder', ids, {params:{
      status:state
    }}
    )
  }//审核采购需求
  deletePurchaseRequirement(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchPurchaseRequiredOrder', options)
  }//删除采购需求
  importPurchaseRequirementFromExcel(file:File){
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);
    return this.http.post(environment.apiUrl + '/Excel' + '/ImportPurchaseRequirement', formData, { responseType: 'blob'
    });
  }//导入采购需求
  exportPurchaseRequirementToExcel(){
    return this.http.get(environment.apiUrl + '/Excel' + '/ExportPurchaseRequirement', { responseType: 'blob'})
  }//导出采购需求
  exportPurchaseRequirementToExcelModel(){
    return this.http.get(environment.apiUrl + '/Excel' + '/ExportPurchaseRequirementModel', { responseType: 'blob'})
  }//导出采购需求模板
  getPurchaseRequirementPart(filter:{
    PageSize?:number,
    PageNumber?:number,
    StartTime?:string,
    EndTime?:string,
    PurchaseRequiredNum?:string,
    PartNumPartName?:string,
    PurchaseManNumPurchaseManName?:string,
    Status?:string,
    isClosed: boolean,
    ZhuanHuanWanDe?:boolean,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPagedPurchaseRequiredOrderParts', {params:filter})
  }//获取采购需求物料
  getPaurchaseOrder(filter:{
    PageSize?:number,
    PageNumber?:number,
    PurchaseOrderNum?:string,
    Part?:string,
    Supply?:string,
    Status?:string,
    isClosed?:boolean,
    StartTime?:string,
    EndTime?:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseOrderWithSub', {params:filter})
  }//获取采购订单
  addPurchaseOrder(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreatePurchaseOrder', data)
  }//新增采购订单
  getPurchaseOrderById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseOrderById', {params:{
      purchaseOrderId:id
    }})
  }//获取采购订单详情
  editPurchaseOrder(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdatePurchaseOrder', data, {params:{purchaseOrderId:id}})
  }//编辑采购订单
  closePurchaseOrder(idS:any){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseOrder', idS)
  }//结案采购订单
  auditPurchaseOrder(state:any,ids:any){
    return this.http.put(environment.apiUrl + this.data + '/ChangePurchaseOrder', ids, {params:{
      status:state
    }}
    )
  }//审核采购订单

  deletePurchaseOrder(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchPurchaseOrder', options)
  }//删除采购订单
  importPurchaseOrderFromExcel(file:File){
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);
    return this.http.post(environment.apiUrl + '/Excel' + '/ImportPurchaseOrder', formData, { responseType: 'blob'
    });
  }//导入采购订单
  exportPurchaseOrderToExcel(){
    return this.http.get(environment.apiUrl + '/Excel' + '/ExportPurchaseOrder', { responseType: 'blob'})
  }//导出采购订单
  exportPurchaseOrderToExcelModel(){
    return this.http.get(environment.apiUrl + '/Excel' + '/ExportPurchaseOrderModel', { responseType: 'blob'})
  }//导出采购订单模板
  getPurchaseOrderPart(filter:{
    PageSize?:number,
    PageNumber?:number,
    StartTime?:string,
    EndTime?:string,
    PurchaseOrderNum?:string,
    Part?:string,
    Supply:string,
    Status?:string,
    isClosed:boolean,
    ZhuanHuanWanDe?:boolean,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPagedPurchaseOrderParts', {params:filter})
  }
  addPurchaseArrival(data:any,qRCodeConfigurationId:any){
    return this.http.post(environment.apiUrl + this.data + '/CreatePurchaseArrivalOrder', data,{params:{qRCodeConfigurationId:qRCodeConfigurationId}})
  }//新增采购到货
  getPurchaseArrivalById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseArrivalOrderById', {params:{
      purchaseArrivalOrderId:id
    }})
  }//获取采购到货详情
  editPurchaseArrival(id:any, data:any,qRCodeConfigurationId:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdatePurchaseArrivalOrder', data, {params:{purchaseArrivalOrderId:id,qRCodeConfigurationId:qRCodeConfigurationId}})
  }//编辑采购到货
  closePurchaseArrival(idS:any){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseArrival', idS)
  }//结案采购到货
  auditPurchaseArrival(state:any,ids:any){
    return this.http.put(environment.apiUrl + this.data + '/ChangePurchaseArrivalOrder', ids, {params:{
      status:state
    }}
    )
  }//审核采购到货
  deletePurchaseArrival(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchPurchaseArrivalOrder', options)
  }//删除采购到货
  GetPurchaseArrivalOrderWithSub(
    filter:{
      PageSize?:number,
      PageNumber?:number,
      PurchaseArrivalOrderNum?:string,
      Part?:string,
      Supply?:string,
      Status?:string,
      isClosed?:string,
      StartTime?:string,
      EndTime?:string,
    }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseArrivalOrderWithSub', {params:filter})
  }//获取采购到
  GetPagedPurchaseArrivalOrderParts(
    filter:{
      PageSize?:number,
      PageNumber?:number,
      StartTime?:string,
      EndTime?:string,
      PurchaseArrivalOrderNum?:string,
      PurchaseReturnedOrderNum?:string,
      isClosed?:boolean,
      Supply:string,
      Status?:string,
      Part?:string,
      ZhuanHuanWanDe?:boolean,
    }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPagedPurchaseArrivalOrderParts', {params:filter})
  }//获取采购到货物料
  getPurchaseReturn(filter:{
    PageSize?:number,
    PageNumber?:number,
    StartTime?:string,
    EndTime?:string,
    PurchaseArrivalOrderNum?:string,
    PurchaseReturnedOrderNum?:string,
    isClosed?:boolean,
    Supply?:string,
    Part?:string,
    Status?:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseReturnedOrderWithSub', {params:filter})
  }
  addPurchaseReturn(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreatePurchaseReturnedOrder', data)
  }//新增采购退货
  getPurchaseReturnById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseReturnedOrderById', {params:{
      purchaseReturnedOrderId:id
    }})
  }//获取采购退货详情
  editPurchaseReturn(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdatePurchaseReturnedOrder', data, {params:{purchaseReturnedOrderId:id}})
  }//编辑采购退货
  closePurchaseReturn(idS:any){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseReturn', idS)
  }//结案采购退货
  auditPurchaseReturn(state:any,ids:any){
    return this.http.put(environment.apiUrl + this.data + '/ChangePurchaseReturnedOrder', ids, {params:{
      status:state
    }}
    )
  }//审核采购退货
  deletePurchaseReturn(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchPurchaseReturnedOrder', options)
  }//删除采购退货
  getPurchaseReturnPart(
    filter:{
      PageSize?:number,
      PageNumber?:number,
      SearchTerm?:string,
      part?:string,
      supply:string,
      status?:string,
      isClosed?:string,
      startTime?:string,
      endTime?:string,
    }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseReturnPartWithSub', {params:filter})
  }//获取采购退货物料
  getPurchaseArrivalPartByPartId(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseArrivalPartWithSub', {params:{
      partId:id
    }})
  }//获取采购到货物料详情
  getPurchaseReturnPartByPartId(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseReturnPartWithSub', {params:{
      partId:id
    }})
  }//获取采购退货物料详情
  PurchaseReturnById(id:any){
    return this.http.post(environment.apiUrl + this.data + '/PurchaseReturned', null,{params:{
      id:id
    }})
  }
  PurchaseArrival(id: any, data: any) {
    const url = `${environment.apiUrl}${this.data}/PurchaseArrival`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json'
    });

    return this.http.post(url, data, { headers, params: { id: id } });
  }
  GetLogsByPurchaseRequiredOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByPurchaseRequiredOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllPurchaseRequiredOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllPurchaseRequiredOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllPurchaseOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllPurchaseOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByPurchaseOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByPurchaseOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllPurchaseArrivalOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllPurchaseArrivalOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByPurchaseArrivalOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByPurchaseArrivalOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllPurchaseReturnedOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllPurchaseReturnedOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByPurchaseReturnedOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByPurchaseReturnedOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByOutsourcingOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByOutsourcingOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllOutsourcingOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllOutsourcingOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByOutsourcingArrivalOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByOutsourcingArrivalOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllOutsourcingArrivalOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllOutsourcingArrivalOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetLogsByOutsourcingReturnedOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByOutsourcingReturnedOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllOutsourcingReturnedOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllOutsourcingReturnedOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  ClosePurchaseRequiredOrder(data:any,isClosed:boolean){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseRequiredOrder', data,{params:{
      close:isClosed
    }})
  }
  ClosePurchaseRequiredOrderPart(data:any,isClosed:boolean){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseRequiredOrderPart', data,{params:{
      close:isClosed
    }})
  }
  ClosePurchaseOrder(data:any,isClosed:boolean){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseOrder', data,{params:{
      close:isClosed
    }})
  }
  ClosePurchaseOrderPart(data:any,isClosed:boolean){
    return this.http.put(environment.apiUrl + this.data + '/ClosePurchaseOrderPart', data,{params:{
      close:isClosed
    }})
  }
  GetPurchaseInspectionOrder(filter:{
    PageSize?:number,
    PageNumber?:number,
    StartTime?:string,
    EndTime?:string,
    PurchaseInspectionOrderNum?:string,
    Part?:string,
    Status?:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseInspectionOrder', {params:filter})
  }
  GetPurchaseInspectionOrderById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchaseInspectionOrderById', {params:{
      purchaseInspectionOrderId:id
    }})
  }
  ChangePurchaseInspectionOrder(purchaseInspectionId: number, quantities: number) {
    return this.http.post(environment.apiUrl + this.data + '/ChangePurchaseInspectionOrder', null, {
      params: {
        purchaseInspectionId: purchaseInspectionId,
        quantities: quantities
      }
    });
  }
  GetLogsByPurchaseInspectionOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByPurchaseInspectionOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllPurchaseInspectionOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllPurchaseInspectionOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }

  GetOutsourcingInspectionOrder(filter:{
    PageSize?:number,
    PageNumber?:number,
    StartTime?:string,
    EndTime?:string,
    OutsourcingInspectionOrderNum?:string,
    Part?:string,
    Status?:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data + '/GetOutsourcingInspectionOrder', {params:filter})
  }
  GetLogsByOutsourcingInspectionOrderId(id:any,pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetLogsByOutsourcingInspectionOrderId', {params:{
      Id:id,
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  GetAllOutsourcingInspectionOrderLogs(pageNumber:any,pageSize:any){
    return this.http.get(environment.apiUrl + this.data + '/GetAllOutsourcingInspectionOrderLogs', {params:{
      PageNumber:pageNumber,
      PageSize:pageSize
    }})
  }
  ChangeOutsourcingInspectionOrder(outsourcingInspectionId: number, quantities: number, note: string) {
    return this.http.post(environment.apiUrl + this.data + '/ChangeOutsourcingInspectionOrder', null, {
      params: {
        outsourcingInspectionId: outsourcingInspectionId,
        quantities: quantities,
        note: note
      }
    });
  }
  CreateOrUpdateInspectionOrderTemporary(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreateOrUpdateInspectionOrderTemporary', data)
  }
  GetInspectionOrderTemporaryByNum(orderNum:any){
    return this.http.get(environment.apiUrl + this.data + '/GetInspectionOrderTemporaryByNum', {params:{
      orderNum:orderNum
    }})
  }
}
